package com.qingcheng.controller;

import com.alibaba.dubbo.config.annotation.Reference;
import com.qingcheng.pojo.seckill.SeckillGoods;
import com.qingcheng.service.seckill.SeckillGoodsService;
import com.qingcheng.util.DateUtil;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;
import java.util.List;

/**
 * @author 岳剑飞
 * @Company http://www.ithiema.com
 */
@RestController
@RequestMapping("/seckill/goods")
public class SeckillGoodsController {

    @Reference
    private SeckillGoodsService seckillGoodsService;

    /**
     * 获取时间菜单
     * url:  /seckill/goods/menus
     *
     * @return
     */
    @GetMapping("/menus")
    public List<Date> dateMenus() {
        List<Date> dateMenus = DateUtil.getDateMenus();
        return dateMenus;

    }

    /**
     * url:  /seckill/goods/list
     * 对应时间段秒杀商品集合查询
     *
     * @param time
     * @return
     */
    @GetMapping("/list")
    public List<SeckillGoods> list(String time) {
        //调用Service 查询数据
        List<SeckillGoods> list = seckillGoodsService.list(DateUtil.formatStr(time));
        return list;
    }

    /**
     * url: /seckill/goods/one
     * 根据id查询商品详情
     *
     * @param time
     * @param id
     * @return
     */
    @GetMapping("/one")
    public SeckillGoods one(String time, Long id) {
        //调用service查询商品详情
        return seckillGoodsService.one(time, id);
    }

}
